package io.github.zerobyteword.oneasynctool;

import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicLong;

public class RejectHandler implements RejectedExecutionHandler {
    private AtomicLong value = new AtomicLong(0);

    public long getValue() {
        return value.get();
    }

    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
        value.incrementAndGet();
        throw new RejectedExecutionException("Task " + r.toString() +
                " rejected from " +
                e.toString());
    }
}
